<!--反馈页面-->
<template>
  <div class="user">
    <div class="handle">
      <el-select v-model="value" placeholder="请选择">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-select v-model="params.status" placeholder="请选择">
        <el-option
          v-for="item in data"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-button type="primary" @click="getBack">查找</el-button>
    </div>
    <div class="handle">
      <el-table
        v-loading="isLoading"
        :data="backList"
        style="width: 100%"
      >
        <el-table-column
          label="反馈用户"
          align="center"
          prop="nickname"
        />
        <el-table-column
          label="反馈意见"
          align="center"
          prop="content"
        />
        <el-table-column
          label="状态"
          prop="feedback_status"
          align="center"
        >
          <template slot-scope="scope">
            <el-tag size="small" :type="scope.row.feedback_status === 1 ? 'primary' : 'danger'">{{ scope.row.feedback_status === 1?"已处理":"未处理" }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
        >
          <template slot-scope="scope">
            <el-button :disabled="scope.row.feedback_status!==0" type="success" @click="backQuery(scope.row)">反馈处理</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="反馈处理"
        :visible.sync="dialogVisible"
        width="30%"
      >
        <el-form label-width="80px">
          <el-form-item label="反馈意见">
            <el-input v-model="result" />
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="updateResult">确 定</el-button>
        </span>
      </el-dialog>
      <el-pagination
        :current-page="params.page"
        :page-sizes="[5, 10, 20,30]"
        :page-size="params.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { getFeedBackList, setFeedBack } from '@/api/feedback'

export default {
  name: 'Index',
  data() {
    return {
      data: [
        {
          value: '',
          label: '所有'
        }, {
          value: '1',
          label: '已处理'
        }, {
          value: '0',
          label: '未处理'
        }],
      isLoading: false,
      value: '1',
      params: {
        page: 1,
        size: 10,
        status: ''
      },
      options: [{
        value: '1',
        label: '建议'
      }, {
        value: '0',
        label: '投诉'
      }],
      backList: {},
      result: '',
      dialogVisible: false,
      id: 0,
      total: 0
    }
  },
  // 进入页面时候渲染
  async created() {
    await this.getUserDemo(this.value, this.params)
  },
  // 获取反馈
  methods: {
    async getUserDemo(type, params) {
      this.isLoading = true
      const res = await getFeedBackList(type, params)
      console.log(res.data.feedBacks.total)
      this.backList = res.data.feedBacks.records
      this.total = res.data.feedBacks.total
      this.isLoading = false
    },
    // 反馈类型查找
    async getBack() {
      await this.getUserDemo(this.value, this.params)
    },
    // 反馈处理
    backQuery(row) {
      this.result = row.result
      this.dialogVisible = true
      this.id = row.id
    },
    // 反馈提交
    updateResult() {
      const params = {
        id: this.id,
        result: this.result
      }
      setFeedBack(params)
      this.getUserDemo(this.value, this.params)
      this.dialogVisible = false
    },
    // 分页器
    handleSizeChange(e) {
      this.params.size = e
      this.getUserDemo(this.value, this.params)
    },
    handleCurrentChange(e) {
      this.params.page = e
      this.getUserDemo(this.value, this.params)
    }

  }
}
</script>

<style scoped>
.el-select{
  margin: 0 30px 10px 0;
}
.user {
  padding: 10px;
  min-height: 100vh;
}
.handle{
  background-color: white;
  margin-top: 10px;
  padding: 30px 10px 10px 10px;
  border-radius: 10px;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
}
</style>
